<?php

namespace App\Http\Middleware;

use Closure;
use App\Good;

/**
*检测选中的商品是否存在
*@return 存在继续进行，否则返回false
*/

class GoodsExistCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {   
        //在这里访问req里的地址栏get参数用使用路由里定义的形式参数
        //获取商品id
        $gid = $request->id;
        //获取商品数量
        $num = $request->num;
        $goods = Good::find($gid);
        if($goods){
            return $next($request);
        }else {
            return 0;
        }
    }
}
